using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using MCWEBSITE.BUL;
using MCWEBSITE.ENTITY;

public partial class Modules_DVPJSC_wucDVPRelatedProduct : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            int ItemId = Convert.ToInt32(Request.QueryString["ItemId"]);
            this.BindData(ItemId);
        }
    }
    protected void BindData(int ItemId)
    {
        string Language = "vi-VN";
        
        websiteProductInfo obj = new websiteProductInfo();
        obj = websiteProductBUL.Load(ItemId);
        int CatID = obj.CategoryID;
        List<websiteProductInfo> lstwebsiteProductInfo = new List<websiteProductInfo>();
        lstwebsiteProductInfo = websiteProductBUL.SelectNtoMByLanguageAndCat(1, 6, "1", Language, CatID);
        foreach (websiteProductInfo obj1 in lstwebsiteProductInfo)
        {
            string fileName = "";
            DirectoryInfo ThumbDirectory = new DirectoryInfo(Server.MapPath(obj1.Image));
            foreach (FileInfo file in ThumbDirectory.GetFiles())
            {
                if (file.Name != "vssver2.scc" && file.Name != "Thumbs.db")
                {
                    fileName = file.Name.ToString();
                    break;
                }
            }
            obj1.Image += fileName;
            if (obj1.Description.Length >= 20)
                obj1.Description = obj1.Description.Substring(0, 20) + " ...";
        }
        dlProduct.DataSource = lstwebsiteProductInfo;
        dlProduct.DataBind();
    }

    public string ConvertString(string strThumb)
    {
        if (strThumb != "")
            return strThumb.Remove(0, 2);
        return strThumb;
    }

    public string ConvertURL(string strImage)
    {
        try
        {
            string fileName = "";
            DirectoryInfo URL = new DirectoryInfo(Server.MapPath(strImage));
            foreach (FileInfo file in URL.GetFiles())
            {
                if (file.Name != "vssver2.scc" && file.Name != "Thumbs.db")
                {
                    fileName = file.Name.ToString();
                    break;
                }
            }
            return strImage + "/" + fileName.ToString();
        }
        catch
        {
            return "";
        }
    }
}
